package com.clickpaas.workinghours.dao.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.codegen.*;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.*;
import com.clickpaas.workinghours.bean.WorkingHoursDTOBean;
import com.clickpaas.workinghours.dao.WbsDao;
import com.clickpaas.workinghours.entity.WBSEntity;
import com.clickpaas.workinghours.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Repository
public class WbsDaoImpl implements WbsDao {

    @Resource
    private WorkingHoursDTOBean dtoBean;
    @Resource
    private WbsApi wbsApi;
    /**
     * 根据条件查询
     *
     * @param wbsdto
     */
    private List<WBSDTOResponse> getDataByCondtion(WBSDTO wbsdto) {
        DataResponseListWBSDTO dataInfo = wbsApi.findWBSUsingPOST(wbsdto);
        if(null == dataInfo
                || null == dataInfo.getData()
                || dataInfo.getData().size()<=0
                || !"SUCCESS".equals(dataInfo.getMessage())){
            log.info("当前查询的数据：【{}】",dataInfo);
            return null;
        }
        return dataInfo.getData();
    }

    /**
     * 根据条件查询WBS对象数据
     *
     * @param wbsEntity
     */
    @Override
    public List<WBSDTOResponse> queryDataInfo(WBSEntity wbsEntity) {
        WBSDTO wbsdto = dtoBean.wbsdto();
        try {
            SpringUtil.copyPropertiesIgnoreNull(wbsEntity,wbsdto);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",wbsEntity);
        }
        return getDataByCondtion(wbsdto);
    }

    /**
     * 根据Id查询数据
     *
     * @param Id
     */
    @Override
    public WBSDTOResponse queryDataInfoById(String Id) {
        WBSDTO wbsdto = dtoBean.wbsdto();
        wbsdto.setId(Id);
        List<WBSDTOResponse> dataByCondtion = getDataByCondtion(wbsdto);
        if (null == dataByCondtion)return null;
        return dataByCondtion.get(0);
    }

}
